package com.dfbz.demo05_匿名内部类课堂案例;

/**
 * @author lscl
 * @version 1.0
 * @intro:
 */
public class Demo01 {
    public static void main(String[] args) {


        Task downloadTask = new DownloadTask();
        Task uploadTask = new UploadTask();

        /*

        class ChatTask implements Task{
             public void run() {
                System.out.println("聊天任务....");
            }
        }

        Task chatTask = new ChatTask()

         */
        Task chatTask = new Task() {
            @Override
            public void run() {
                System.out.println("聊天任务....");
            }
        };

        Task eatTask = new Task() {
            @Override
            public void run() {
                System.out.println("吃饭任务...");
            }
        };

        Handler handler = new Handler(new Task() {
            @Override
            public void run() {
                System.out.println("跑步任务...");
            }
        });
        handler.doHandler();

    }
}

class UploadTask implements Task{
    @Override
    public void run() {
        System.out.println("上传.......");
    }
}

class DownloadTask implements Task{
    @Override
    public void run() {
        System.out.println("下载任务...");
    }
}


interface Task {
    void run();
}

class Handler {

    private Task task;

    public void doHandler() {

        if (task != null) {
            task.run();
            return;
        }

        System.out.println("task还没有被赋值！");
    }

    public Handler() {
    }

    public Handler(Task task) {
        this.task = task;
    }

    public Task getTask() {
        return task;
    }

    public void setTask(Task task) {
        this.task = task;
    }
}
